﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectEulerSolutions
{
    /*
     * If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.

{20,48,52}, {24,45,51}, {30,40,50}

For which value of p ≤ 1000, is the number of solutions maximised?

     * 
     * */
    class Problem39 : IProblem
    {
        public string Calculate()
        {
            //pojednostavljenje od:
            //a^2 + b^2 = c^2
            //a + b + c = p
            Func<int, int, double> transform = (a, p) => (p * a - p * p / 2) / (double)(a - p);



            int maxCount = 0;
            int maxP = 0;

            for (int p = 1; p < 1000; p++)
            {
                int count = 0;
                for (int a = 1; a < p; a++)
                {
                    double res = transform(a, p);
                    if (res > 0)
                        if ((int)res == res)
                            count++;
                }

                if (count > maxCount)
                {
                    maxCount = count;
                    maxP = p;
                }
            }


            return maxP.ToString();
        }
    }
}
